#!/bin/bash

JAVA=java
HOME=/home/art/workspace2/erdapfel/extra
LIB=$HOME/lib/default
CLASS="org.openstreetmap.osmosis.core.Osmosis"
PLUGINS="-plugin org.openstreetmap.osmosis.core.CorePluginLoader -plugin org.openstreetmap.osmosis.xml.XmlPluginLoader -plugin org.mapsforge.map.writer.osmosis.MapFileWriterPluginLoader "
CLASSPATH="$LIB/osmosis-core*:$LIB/osmosis-pbf*:$LIB/osmosis-xml*:$LIB/*"

MAP_WRITER_LINK=$LIB/map-writer.jar
MAP_WRITER_LIB_INSTALL=/home/art/Documents/PFC2/osmosis-capat/lib/mapsforge-map-writer-0.3.0-jar-with-dependencies.jar

CLEAN=clean

if [ "$1" = $CLEAN ];
then
    echo "Cleaning the lib "$LIB
    rm -f $LIB/aopalliance*jar
    rm -f $LIB/commons-codec*jar
    #rm -f $LIB/commons-compress*jar
    rm -f $LIB/commons-dbcp*jar
    #rm -f $LIB/commons-logging*jar
    rm -f $LIB/commons-pool*jar
    rm -f $LIB/jpf*jar
    #rm -f $LIB/map-writer.jar
    rm -f $LIB/mysql-connector-java-5.1.18.jar
    rm -f $LIB/osmosis-apidb-*.jar
    rm -f $LIB/osmosis-areafilter-*.jar
    #rm -f $LIB/osmosis-core-*.jar
    rm -f $LIB/osmosis-dataset-*.jar
    rm -f $LIB/osmosis-extract-*.jar
    rm -f $LIB/osmosis-hstore-*.jar
    rm -f $LIB/osmosis-pbf-*.jar
    rm -f $LIB/osmosis-pgsimple-*.jar
    rm -f $LIB/osmosis-pgsnapshot-*.jar
    rm -f $LIB/osmosis-replication-*.jar
    rm -f $LIB/osmosis-set-*.jar
    rm -f $LIB/osmosis-tagfilter-*.jar
    #rm -f $LIB/osmosis-xml-*.jar
    rm -f $LIB/osmpbf-*.jar
    rm -f $LIB/plexus-classworlds*jar
    rm -f $LIB/postgis-jdbc*jar
    rm -f $LIB/postgresql-9.0-801.jdbc4.jar
    rm -f $LIB/protobuf-java*jar
    rm -f $LIB/spring-aop-3.0.6.RELEASE.jar
    rm -f $LIB/spring-asm-3.0.6.RELEASE.jar
    rm -f $LIB/spring-beans-3.0.6.RELEASE.jar
    rm -f $LIB/spring-context-3.0.6.RELEASE.jar
    rm -f $LIB/spring-core-3.0.6.RELEASE.jar
    rm -f $LIB/spring-expression-3.0.6.RELEASE.jar
    rm -f $LIB/spring-jdbc-3.0.6.RELEASE.jar
    rm -f $LIB/spring-tx-3.0.6.RELEASE.jar
    rm -f $LIB/stax2-api*jar
    rm -f $LIB/woodstox-core-lgpl*jar
    rm -f $LIB/xercesImpl*jar
else
    echo "Not cleaning the lib"
fi

if [ ! -f $MAP_WRITER_LINK ];
then
	echo "Creating a link to the mapsforge-map-witer tuned library" &&
	cp $MAP_WRITER_LIB_INSTALL $MAP_WRITER_LINK
fi

CMD="--read-xml file=data/map.osm --sort --mapfile-writer type=hd file=/tmp/map.map bbox=2.47,41.80,2.54,41.84 polygon-clipping=false way-clipping=false label-position=false simplification-factor=25"

echo "*** Executing: ***" && echo "->"$CMD && $JAVA -cp $CLASSPATH -Dapp.home=$HOME $CLASS $PLUGINS$CMD
